package com.dongge.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * Created by dongge on 16/8/3.
 */
@Aspect
@Component
public class AopHelper {

    @Before("execution (* com.dongge.aop.A.print(..))")
    public void someOp(){
        System.out.println("Before print called");
    }

//  @Before("com.dongge.aop.A.output()")
//    @Before("execution (* com.dongge.aop.A.output(..))")

    /**
     * 使用公共切入点表达式
     */
    @Before("com.dongge.aop.BussinessAop.dataAccessOp()")
    public void someOutput(){
        System.out.println("Output before advice");
    }

    @Around("execution (* com.dongge.aop.A.delete(..))")
    public void aopDelete(ProceedingJoinPoint proceedingJoinPoint){

    }

//    @Before("execution (* com.dongge.aop.A.setName(..)) && args(name)")
    @Before("args(name)")
    public void getArgs(String name){
        System.out.println(name);
    }

    /**
     *
     * 下面的例子可以看出几个问题:
     * @annotation(com.dongge.aop.IRight)能够匹配带有IRigth注解的方法
     * @annotation(right)在配合getAnnotation(IRight right)情况下
     * 也能匹配这个方法并且能够获取注解中的值
     *
     */

//    @Before("@annotation(com.dongge.aop.IRight)")
//    @Before("@annotation(com.dongge.aop.IRight) && @annotation(right)")
    @Before("@annotation(right)")
//    public void getAnno(){
    public void getAnnotation(IRight right){
        System.out.println(right.value());
    }
}
